package me.zk.practice1.s;

import java.util.HashMap;
import java.util.Map;

/**
 * 70. 爬楼梯
 * @author zhangkai
 * @date 2023/7/6 09:33
 */
public class LS70 {
    public Map<Integer,Integer> map = new HashMap<>();
    public int climbStairs(int n) {
        if (n == 1) return 1;
        if (n == 2) return 2;
        if (map.containsKey(n)) {
            return map.get(n);
        } else {
            int result = climbStairs(n-1) + climbStairs(n-2);
            map.put(n,result);
            return result;
        }
    }
    public int climbStairs2(int n) {
        if (n == 1) return 1;
        if (n == 2) return 2;
        int result = 0;

        int pre = 2;
        int ppre = 1;
        for (int i = 3; i <= n; i++) {
            result = pre + ppre;
            ppre = pre;
            pre = result;
        }
        return result;
    }

}
